<?php   // $Id: backup_action.php 347 2012-05-07 09:11:55Z pcoustillas $ ?>
<?php
/*
Copyright (C) 2003-2004 Guy Hendrickx
Licensed under the terms of the GNU  General Public License:http://www.opensource.org/licenses/gpl-license.php
File Authors: Pierre Coustillas
*/

require_once("include/verif.php");
require_once("include/config/common.php");
require_once("include/utils.php");

$file=isset($_POST['nom_backup'])?$_POST['nom_backup']:"";

if ($file=="")
{
	header("Location: backup_accueil.php?message=Vous n'avez pas indiqué de fichier !");
	exit;

}

// l'utilisateur à demandé une suppression
if (isset($_POST['delete']))
{
	
	unlink("dump/$file");
	header("Location: backup_accueil.php?message=backup supprimé !");
	exit;

}

// l'utilisateur à demandé une restauration
if (isset($_POST['restaurer']))
{
	$var_sql=file_get_contents("dump/$file");
	$tab_sql=preg_split("/;--FIN--/",$var_sql);

	foreach($tab_sql as $req_sql)
	{
		mysql_query($req_sql) or die ("Erreur restauration du backup<br/>" . mysql_error());
	}

	header("Location: backup_accueil.php?message=backup restauré !");
	exit;

}

// l'utilisateur à demandé un download
if (isset($_POST['download']))
{
	
	$filename = "dump/$file";
	header("Cache-Control: public");
	header("Content-Description: File Transfer");
	header('Content-disposition: attachment; filename='.basename($filename));
	header("Content-Type: text/plain");
	//header("Content-Transfer-Encoding: binary");
	header('Content-Length: '. filesize($filename));
	readfile($filename); 

	//readfile("dump/$file");


}




?>


